package com.changgou.service.goods.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.service.goods.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/spec")
@CrossOrigin
public class SpecController {
    @Autowired
    private SpecService specService;

    @GetMapping("/category/{category}")
    public Result findListByCategoryName(@PathVariable String category) {
        List<Map> list = specService.findListByCategoryName(category);
        for (Map spec : list) {
            System.out.println(spec.get("options"));
            String[] options = ((String) spec.get("options")).split(",");//
            spec.put("options",options);
        }
        return new Result(true, StatusCode.OK, "查询成功", list);
    }
}
